package cn.hhz._07springaop.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.lang.reflect.Array;
import java.util.Arrays;

@Aspect
@Component
public class LogAspect {
//    @Before(value = "execution(public int cn.hhz._07springaop.aop.CalculatorImpl.*(..))")
//    public void before(JoinPoint joinPoint){
//        String name = joinPoint.getSignature().getName();
//        String args = Arrays.toString(joinPoint.getArgs());
//        System.out.println("before"+name+"方法开始了,参数是"+args);
//    }

    @Around(value = "execution(public int cn.hhz._07springaop.aop.CalculatorImpl.*(..))")
    public Object around(ProceedingJoinPoint joinPoint){
        Object result = null;
        System.out.println("huanrao:before");
        try {
            result = joinPoint.proceed();
            System.out.println("huanrao:return");
        } catch (Throwable e) {
            System.out.println("huanrao:yichang");
            throw new RuntimeException(e);
        }finally {
            System.out.println("huanrao:houzhi");
        }
        return result;
    }
}
